package com.mtl.discuss.service.impl;

import com.mtl.discuss.domain.Discuss;
import com.mtl.discuss.mapper.DiscussMapper;
import com.mtl.discuss.service.IDiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.mtl.common.tool.model.Page;

import java.util.List;
/**
 * 评论 服务实现类
 *
 * @author qms
 * @since 2019-08-05
 */
@Service
public class DiscussServiceImpl implements IDiscussService {

    @Autowired
    private DiscussMapper discussMapper;

    @Override
    public Discuss findById(Integer id) {
        return discussMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<Discuss> findPage(Integer page, Integer size,String search) {
        PageHelper.startPage(page,size);
        List<Discuss> discusss=discussMapper.selectByCondition(search);
        return new Page<>(discusss);
    }
    @Override
    public Page<Discuss> findIds(Integer page, Integer size,List<Integer> search) {
        PageHelper.startPage(page,size);
        System.out.println("11||||"+search);
        List<Discuss> discusss=discussMapper.findByUserId(search);
        return new Page<>(discusss);
    }

    @Override
    public int saveOrUpdate(Discuss discuss) {
        if(discuss.getDisId()!=null){
        return discussMapper.updateByPrimaryKey(discuss);
        }
        return discussMapper.insert(discuss);
    }

    @Override
    public int deleteBatch(List<Integer> ids) {
        return discussMapper.deleteByIdList(ids);
    }
    @Override
    public List<Discuss> selectByArticleId(Integer articleId) {
        return discussMapper.selectByArticleId(articleId);
    }
}
